package com.czk.aop.aspectj;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * 增强类
 * @Author:ChenZhangKun
 * @Date: 2020/11/22 21:36
 */
@Aspect
@Component
@Order(2)
public class UserProxy {
    /**
     * 相同切入点的抽取
     */
    @Pointcut(value = "execution(* com.czk.aop.entity.User.add(..))")
    public void pointCommon(){

    }


    /**
     * 前置通知
     */
    @Before(value = "execution(* com.czk.aop.entity.User.add(..))")
    public void before(){
        System.out.println("before");
    }

    /**
     * 后置通知
     */
    @After(value = "pointCommon()")
    public void after(){
        // 环绕通知后执行，方法执行完后执行
        System.out.println("after");
    }

    /**
     * 异常通知
     */
    @AfterThrowing(value = "execution(* com.czk.aop.entity.User.add(..))")
    public void afterThrowing(){
        System.out.println("AfterThrowing");
    }
    @AfterReturning(value = "execution(* com.czk.aop.entity.User.add(..))")
    /**
     * 方法返回结果后执行
     */
    public void afterReturning(){
        System.out.println("afterReturning");
    }
    /**
     * 环绕通知
     * @param proceedingJoinPoint
     * @throws Throwable
     */
    @Around(value = "execution(* com.czk.aop.entity.User.add(..))")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("Around前");
        proceedingJoinPoint.proceed();
        // 返回值之后执行
        System.out.println("Around后");
    }
}
